package com.clickpaas.timelineofUN.service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.bizcloud.ipaas.t7aef1c33e4a445f2833f9d631cb90c38.d20210202091529.model.*;
import com.clickpaas.timelineofUN.common.Response.CommonCode;
import com.clickpaas.timelineofUN.common.Response.ResponseResult;
import com.clickpaas.timelineofUN.dao.ProjectDao;
import com.clickpaas.timelineofUN.dao.ProjectProviderDao;
import com.clickpaas.timelineofUN.dao.SystemUserDao;
import com.clickpaas.timelineofUN.dao.UpdatedynamicsDao;
import com.clickpaas.timelineofUN.entity.ParamEntity.NewsEntity;
import com.clickpaas.timelineofUN.entity.ParamEntity.RetParamEntity;
import com.clickpaas.timelineofUN.entity.ParamEntity.TechnAppEntity;
import com.clickpaas.timelineofUN.service.UserProjectService;
import com.clickpaas.timelineofUN.utils.DataInfoUtil;
import com.clickpaas.timelineofUN.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.*;


@Service
@Slf4j
public class UserProjectServiceImpl implements UserProjectService {

    @Resource
    private SystemUserDao systemUserDao;
    @Resource
    private ProjectProviderDao projectProviderDao;
    @Resource
    private ProjectDao projectDao;
    @Resource
    private UpdatedynamicsDao updatedynamicsDao;

    /**
     * 获取当前用户项目数据
     *
     * @return
     */
    @Override
    public ResponseResult getProjectUserInfo(List<ProjectProviderDTOResponse> projectProviderList) {
        List<ProjectProviderDTO> projectProviderDTOS = DataInfoUtil.castListCopy(projectProviderList, ProjectProviderDTOResponse.class, ProjectProviderDTO.class);
        List userProjectInfo = getProNameTime(projectProviderDTOS);
        if(userProjectInfo.size()>0){
            return new ResponseResult(CommonCode.SUCCESS,userProjectInfo);
        }
        return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
    }

    /**
     * 获取所有用户项目数据
     *
     * @return
     */
    @Override
    public ResponseResult getProjectAllInfo() {
        List<ProjectProviderDTOPageInfoResponse> projectProviderAllData = projectProviderDao.getProjectProviderAllData();
        if (null != projectProviderAllData && projectProviderAllData.size()>0){
            List<ProjectProviderDTO> projectProviderDTOS = DataInfoUtil.castListCopy(projectProviderAllData, ProjectProviderDTOPageInfoResponse.class, ProjectProviderDTO.class);
            List proUpDataInfo = getProNameTime(projectProviderDTOS);
            if(null != proUpDataInfo && proUpDataInfo.size()>0){
                return new ResponseResult(CommonCode.SUCCESS,proUpDataInfo);
            }
        }
        return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
    }

    /**
     * 获取所有用户项目数据，带条件查询
     *
     * @param jsonObject
     * @return
     */
    @Override
    public ResponseResult getProjectAllByCondit(JSONObject jsonObject) {
        String projectProviderName = jsonObject.getString("projectProviderName");
        HashMap<String, String> hashMap = DataInfoUtil.jsonToHashMap(jsonObject);
        if (StringUtils.isBlank(projectProviderName)) return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        //查询单个项目方数据
        List<ProjectProviderDTOResponse> PPData = projectProviderDao.projectproviderByName(projectProviderName);
        if (null != PPData && PPData.size()>0){
            List proUpDataInfo = getProUpDataInfo(PPData,hashMap);
            if(null != proUpDataInfo && proUpDataInfo.size()>0){
                return new ResponseResult(CommonCode.SUCCESS,proUpDataInfo);
            }
        }

        return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
    }

    /**
     * 用户界面获取所有用户项目数据
     *
     * @param jsonObject
     * @return
     */
    @Override
    public ResponseResult getProjectUserByCondit(List<ProjectProviderDTOResponse> projectProviderList,JSONObject jsonObject) {
        String projectName = jsonObject.getString("projectName");
        HashMap<String, String> hashMap = DataInfoUtil.jsonToHashMap(jsonObject);
        if (StringUtils.isNotBlank(projectName)){
            List userProjectInfo = getProUpDataInfo(projectProviderList,hashMap);
            if(null != userProjectInfo && userProjectInfo.size()>0){
                return new ResponseResult(CommonCode.SUCCESS,userProjectInfo);
            }
        }
        return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
    }

    /**
     * 获取用户数据
     *
     * @param token
     * @param jsonObject
     * @return
     */
    @Override
    public ResponseResult getProject(String token, JSONObject jsonObject) {
        /**
         * 登陆用户ID
         */
        String userId = DataInfoUtil.getSysUserIdByHttp(token);
        if (StringUtils.isBlank(userId))return new ResponseResult(CommonCode.AUTHFAIL,new ArrayList<>());
        SystemUserDTOResponse userData = systemUserDao.systemUserByUserId(userId);
        if (null == userData || StringUtils.isBlank(userData.getId())){
            /**
             * 管理员在注册用户表中查询不到数据，走管理员查询逻辑
             */
            return getProjectAllByCondit(jsonObject);
        }else {
            if (StringUtils.isNotBlank(userData.getTypeofPersonnel())){
                if (DataInfoUtil.ifManager(userData.getTypeofPersonnel())){
                    //主任、财务、员工工号当作管理员处理
                    return getProjectAllInfo();
                }
            }
            /**
             * 登陆用户对应的所有项目方数据
             */
            List<ProjectProviderDTOResponse> projectProviderList = projectProviderDao.projectproviderByUserId(userData.getId());
            if (null == projectProviderList
                    || projectProviderList.size()<=0){
                log.info("当前ID：【{}】,在项目方【projectProvider】对象查询的数据是：【{}】",userData.getId(),projectProviderList);
                return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
            }
            return getProjectUserByCondit(projectProviderList,jsonObject);
        }
    }

    /**
     * 获取项目时间线和项目名称
     *
     * @param token
     * @return
     */
    @Override
    public ResponseResult getProNameTime(String token) {
        String userId = DataInfoUtil.getSysUserIdByHttp(token);
        if (StringUtils.isBlank(userId))return new ResponseResult(CommonCode.AUTHFAIL,new ArrayList<>());
        SystemUserDTOResponse userData = systemUserDao.systemUserByUserId(userId);
        if (null == userData || StringUtils.isBlank(userData.getId())){
            return getProjectAllInfo();
        }else {
            if (StringUtils.isNotBlank(userData.getTypeofPersonnel())){
                if (DataInfoUtil.ifManager(userData.getTypeofPersonnel())){
                    //主任、财务、员工工号当作管理员处理
                    return getProjectAllInfo();
                }
            }
            /**
             * 登陆用户对应的所有项目方数据
             */
            List<ProjectProviderDTOResponse> projectProviderList = projectProviderDao.projectproviderByUserId(userData.getId());
            if (null == projectProviderList
                    || projectProviderList.size()<=0){
                log.info("当前ID：【{}】,在项目方【projectProvider】对象查询的数据是：【{}】",userData.getId(),projectProviderList);
                return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
            }
            return getProjectUserInfo(projectProviderList);
        }
    }


    /**
     * 获取用户项目数据
     *
     * @param projectProviderList
     * @return
     */
    public List getProUpDataInfo(List<ProjectProviderDTOResponse> projectProviderList,HashMap<String,String> hashMap){
        /**
         * 所有项目数据
         */
        ArrayList<List<ProjectDTO>> ProjectDataList = new ArrayList<>();
        for (ProjectProviderDTOResponse projectProviderData : projectProviderList){
            if(StringUtils.isNotBlank(projectProviderData.getId())){
                List<ProjectDTO> projectData;
                if (StringUtils.isNotBlank(hashMap.get("projectName"))){
                    projectData = DataInfoUtil.castListCopy(projectDao.projectByProejct(projectProviderData.getId(), hashMap.get("projectName")), ProjectDTOResponse.class, ProjectDTO.class);
                }else {
                    projectData = DataInfoUtil.castListCopy(projectDao.projectByProejct(projectProviderData.getId()), ProjectDTOResponse.class, ProjectDTO.class);
                }
                if(null != projectData || projectData.size()>0){
                    ProjectDataList.add(projectData);
                }
            }
        }
        if (ProjectDataList.size()<=0){
            return null;
        }
        if (StringUtils.isBlank(hashMap.get("year")))return null;
        String year = hashMap.get("year");

        ArrayList<RetParamEntity> lists = new ArrayList<>();
        for (List<ProjectDTO> projectDatas : ProjectDataList){
            if (null == projectDatas || projectDatas.size()<=0)continue;
            /**
             * 多线程处理数据
             */
            ExecutorService projectpool = Executors.newCachedThreadPool();
            CountDownLatch projectlatch = new CountDownLatch(projectDatas.size());
            for (ProjectDTO projectData : projectDatas){
                /**
                 * 开启线程
                 */
                Runnable run = new Runnable() {
                    public void run() {
                        try {
                            if (null == projectData ){
                                log.info("当前ID：【{}】,在项目【project】对象查询的数据是：【{}】",projectData.getId(),projectData);
                                return;
                            }
                            //项目入场数据
                            if(DataInfoUtil.strContain(projectData.getCreatedTime(),year)){
                                RetParamEntity retParamEntity = new RetParamEntity();
                                retParamEntity.setId(projectData.getId());
                                retParamEntity.setYyMmDd(projectData.getCreatedTime());
                                retParamEntity.setMmDd(projectData.getCreatedTime().substring(5,10));
                                retParamEntity.setSortDate(projectData.getCreatedTime());
                                NewsEntity newsEntity = new NewsEntity();
                                StringBuffer stringBuffer = new StringBuffer();
                                stringBuffer.append("项目名称 Project Name:");
                                if (StringUtils.isNotBlank(projectData.getProjectName())){
                                    stringBuffer.append(projectData.getProjectName());
                                }
                                /*stringBuffer.append(" || 创建时间 Created Time:");
                                if (StringUtils.isNotBlank(projectData.getCreatedTime())){
                                    stringBuffer.append(projectData.getCreatedTime());
                                }*/
                                stringBuffer.append("|| 项目入场 Commencement");
                                newsEntity.setTitle(stringBuffer.toString());
                                ArrayList<NewsEntity> newsEntities = new ArrayList<>();
                                newsEntities.add(newsEntity);
                                retParamEntity.setNews(newsEntities);
                                lists.add(retParamEntity);
                            }
                            //项目状态数据
                            String status = DataInfoUtil.getSingleSelection(projectData.getStatus());
                            if ("已对接 Docked".equals(status)){
                                if(DataInfoUtil.strContain(projectData.getStatusUpdateTime(),year)){
                                    RetParamEntity retParamEntity = new RetParamEntity();
                                    retParamEntity.setId(projectData.getId());
                                    retParamEntity.setYyMmDd(projectData.getStatusUpdateTime());
                                    retParamEntity.setMmDd(projectData.getStatusUpdateTime().substring(5,10));
                                    retParamEntity.setSortDate(projectData.getCreatedTime());
                                    NewsEntity newsEntity = new NewsEntity();
                                    StringBuffer stringBuffer = new StringBuffer();
                                    stringBuffer.append("项目名称 Project Name:");
                                    if (StringUtils.isNotBlank(projectData.getProjectName())){
                                        stringBuffer.append(projectData.getProjectName());
                                    }
                                    stringBuffer.append("|| 状态 Status:");
                                    stringBuffer.append(status);
                                    /*stringBuffer.append(" || 状态修改时间 Update Time of Status:");
                                    if (StringUtils.isNotBlank(projectData.getStatusUpdateTime())){
                                        stringBuffer.append(projectData.getStatusUpdateTime());
                                    }*/
                                    newsEntity.setTitle(stringBuffer.toString());
                                    ArrayList<NewsEntity> newsEntities = new ArrayList<>();
                                    newsEntities.add(newsEntity);
                                    retParamEntity.setNews(newsEntities);
                                    lists.add(retParamEntity);
                                }
                            }
                            if (StringUtils.isBlank(projectData.getId()))return;
                            List<UpdateDynamicsDTOResponse> updateNamicsList = updatedynamicsDao.getUpdateNamicsByProId(projectData.getId());
                            if(null != updateNamicsList && updateNamicsList.size()>0){
                                /**
                                 * 多线程处理数据
                                 */
                                ExecutorService updateDynamicpool = Executors.newCachedThreadPool();
                                CountDownLatch updateDynamiclatch = new CountDownLatch(updateNamicsList.size());
                                for (UpdateDynamicsDTOResponse updateDynamic : updateNamicsList){
                                    /**
                                     * 开启线程
                                     */
                                    Runnable run = new Runnable() {
                                        public void run() {
                                            try {
                                                //获奖情况
                                                if(DataInfoUtil.strContain(updateDynamic.getAwardDate(),year)){
                                                    RetParamEntity retParamEntity = new RetParamEntity();
                                                    retParamEntity.setId(updateDynamic.getId());
                                                    retParamEntity.setYyMmDd(updateDynamic.getAwardDate());
                                                    retParamEntity.setMmDd(updateDynamic.getAwardDate().substring(5,10));
                                                    retParamEntity.setSortDate(updateDynamic.getCreatedTime());
                                                    NewsEntity newsEntity = new NewsEntity();
                                                    StringBuffer stringBuffer = new StringBuffer();
                                                    stringBuffer.append("获奖 Award:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getAward())){
                                                        stringBuffer.append(updateDynamic.getAward());
                                                    }
                                                    /*stringBuffer.append(" || 获奖时间 Award Date:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getAwardDate())){
                                                        stringBuffer.append(updateDynamic.getAwardDate());
                                                    }*/
                                                    newsEntity.setTitle(stringBuffer.toString());
                                                    ArrayList<NewsEntity> newsEntities = new ArrayList<>();
                                                    newsEntities.add(newsEntity);
                                                    retParamEntity.setNews(newsEntities);
                                                    lists.add(retParamEntity);
                                                }
                                                //融资
                                                if(DataInfoUtil.strContain(updateDynamic.getFinancingPeriod(),year)){
                                                    //融资轮次特殊处理
                                                    RetParamEntity retParamEntity = new RetParamEntity();
                                                    retParamEntity.setId(updateDynamic.getId());
                                                    retParamEntity.setYyMmDd(updateDynamic.getFinancingPeriod());
                                                    retParamEntity.setMmDd(updateDynamic.getFinancingPeriod().substring(5,10));
                                                    retParamEntity.setSortDate(updateDynamic.getCreatedTime());
                                                    NewsEntity newsEntity = new NewsEntity();
                                                    StringBuffer stringBuffer = new StringBuffer();
                                                    stringBuffer.append("融资轮次 Financing Round:");
                                                    String financingRound = DataInfoUtil.getSingleSelection(updateDynamic.getLastFinancingRound());
                                                    if (StringUtils.isBlank(financingRound)){
                                                        if (StringUtils.isNotBlank(updateDynamic.getLastFinancingRoundOthers())){
                                                            stringBuffer.append(updateDynamic.getLastFinancingRoundOthers());
                                                        }
                                                    }else {
                                                        stringBuffer.append(financingRound);
                                                    }
                                                    stringBuffer.append(" || 融资金额 Financing Amount:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getLastFinancingAmount())){
                                                        stringBuffer.append(updateDynamic.getLastFinancingAmount());
                                                    }
                                                    /*stringBuffer.append(" || 融资时间 Financing Period:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getFinancingPeriod())){
                                                        stringBuffer.append(updateDynamic.getFinancingPeriod());
                                                    }*/
                                                    newsEntity.setTitle(stringBuffer.toString());
                                                    ArrayList<NewsEntity> newsEntities = new ArrayList<>();
                                                    newsEntities.add(newsEntity);
                                                    retParamEntity.setNews(newsEntities);
                                                    lists.add(retParamEntity);
                                                }
                                                //市场开拓
                                                if(DataInfoUtil.strContain(updateDynamic.getMarketDevelopmentDate(),year)){
                                                    RetParamEntity retParamEntity = new RetParamEntity();
                                                    retParamEntity.setId(updateDynamic.getId());
                                                    retParamEntity.setYyMmDd(updateDynamic.getMarketDevelopmentDate());
                                                    retParamEntity.setMmDd(updateDynamic.getMarketDevelopmentDate().substring(5,10));
                                                    retParamEntity.setSortDate(updateDynamic.getCreatedTime());
                                                    NewsEntity newsEntity = new NewsEntity();
                                                    StringBuffer stringBuffer = new StringBuffer();
                                                    stringBuffer.append("市场开拓 Market Development:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getMarketDevelopment())){
                                                        stringBuffer.append(updateDynamic.getMarketDevelopment());
                                                    }
                                                    /*stringBuffer.append(" || 市场开拓日期 Market Development Date:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getMarketDevelopmentDate())){
                                                        stringBuffer.append(updateDynamic.getMarketDevelopmentDate());
                                                    }*/
                                                    newsEntity.setTitle(stringBuffer.toString());
                                                    ArrayList<NewsEntity> newsEntities = new ArrayList<>();
                                                    newsEntities.add(newsEntity);
                                                    retParamEntity.setNews(newsEntities);
                                                    lists.add(retParamEntity);
                                                }
                                                //市场
                                                if(DataInfoUtil.strContain(updateDynamic.getTimetoMarket(),year)){
                                                    RetParamEntity retParamEntity = new RetParamEntity();
                                                    retParamEntity.setId(updateDynamic.getId());
                                                    retParamEntity.setYyMmDd(updateDynamic.getTimetoMarket());
                                                    retParamEntity.setMmDd(updateDynamic.getTimetoMarket().substring(5,10));
                                                    retParamEntity.setSortDate(updateDynamic.getCreatedTime());
                                                    NewsEntity newsEntity = new NewsEntity();
                                                    StringBuffer stringBuffer = new StringBuffer();
                                                    stringBuffer.append("上市地点 Listing Location:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getListingLocation())){
                                                        stringBuffer.append(updateDynamic.getListingLocation());
                                                    }
                                                    /*stringBuffer.append(" || 上市时间 Time to Market:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getTimetoMarket())){
                                                        stringBuffer.append(updateDynamic.getTimetoMarket());
                                                    }*/
                                                    newsEntity.setTitle(stringBuffer.toString());
                                                    ArrayList<NewsEntity> newsEntities = new ArrayList<>();
                                                    newsEntities.add(newsEntity);
                                                    retParamEntity.setNews(newsEntities);
                                                    lists.add(retParamEntity);
                                                }
                                                //技术
                                                if(DataInfoUtil.strContain(updateDynamic.getTechnologyAuthenticationDate(),year)){
                                                    RetParamEntity retParamEntity = new RetParamEntity();
                                                    retParamEntity.setId(updateDynamic.getId());
                                                    retParamEntity.setYyMmDd(updateDynamic.getTechnologyAuthenticationDate());
                                                    retParamEntity.setMmDd(updateDynamic.getTechnologyAuthenticationDate().substring(5,10));
                                                    retParamEntity.setSortDate(updateDynamic.getCreatedTime());
                                                    NewsEntity newsEntity = new NewsEntity();
                                                    StringBuffer stringBuffer = new StringBuffer();
                                                    stringBuffer.append("技术认定 Technology Authentication:");
                                                    String technologyAuthentication = DataInfoUtil.getSingleSelection(updateDynamic.getTechnologyAuthentication());
                                                    if (StringUtils.isNotBlank((technologyAuthentication))){
                                                        stringBuffer.append(technologyAuthentication);
                                                    }
                                                    stringBuffer.append(" || 技术应用领域 Technology Application:");
                                                    if (StringUtils.isBlank(updateDynamic.getTechnologyApplication())){
                                                        if (StringUtils.isNotBlank(updateDynamic.getTechnologyApplicationOthers())){
                                                            stringBuffer.append(updateDynamic.getTechnologyApplicationOthers());
                                                        }
                                                    }else {
                                                        List<TechnAppEntity> stringToList = JsonUtil.getStringToList(updateDynamic.getTechnologyApplication(), TechnAppEntity.class);
                                                        for (TechnAppEntity data : stringToList){
                                                            if (StringUtils.isNotBlank(data.getName())){
                                                                stringBuffer.append(data.getName());
                                                            }
                                                        }
                                                    }
                                                    stringBuffer.append(" || 技术阶段 Stage of Development:");
                                                    String stageDevelopment = DataInfoUtil.getSingleSelection(updateDynamic.getStageofDevelopment());
                                                    if (StringUtils.isBlank(stageDevelopment)){
                                                        if (StringUtils.isNotBlank(updateDynamic.getStageofDevelopmentOthers())){
                                                            stringBuffer.append(updateDynamic.getStageofDevelopmentOthers());
                                                        }
                                                    }else {
                                                        stringBuffer.append(stageDevelopment);
                                                    }
                                                    /*stringBuffer.append(" || 技术认定日期 Technology Authentication Date:");
                                                    if (StringUtils.isNotBlank(updateDynamic.getTechnologyAuthenticationDate())){
                                                        stringBuffer.append(updateDynamic.getTechnologyAuthenticationDate());
                                                    }*/
                                                    newsEntity.setTitle(stringBuffer.toString());
                                                    ArrayList<NewsEntity> newsEntities = new ArrayList<>();
                                                    newsEntities.add(newsEntity);
                                                    retParamEntity.setNews(newsEntities);
                                                    lists.add(retParamEntity);
                                                }
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            } finally {
                                                updateDynamiclatch.countDown();
                                            }
                                        }
                                    };
                                    updateDynamicpool.execute(run);
                                }try {
                                    updateDynamiclatch.await(10, TimeUnit.SECONDS);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }finally {
                                    updateDynamicpool.shutdown();
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            projectlatch.countDown();
                        }
                    }
                };
                projectpool.execute(run);
            }try {
                projectlatch.await(10, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                projectpool.shutdown();
            }
        }
        if (lists.size()>0){
            DataInfoUtil.sortEntity(lists);
        }
        return lists;
    }

    /**
     * 获取项目方名称和项目名称以及项目时间线
     *
     * @param projectProviderList
     * @return
     */
    private List getProNameTime(List<ProjectProviderDTO> projectProviderList){
        ArrayList<Object> lists = new ArrayList<>();
        for (ProjectProviderDTO projectProviderData : projectProviderList){
            if(StringUtils.isBlank(projectProviderData.getId()))continue;
            //所有项目数据
            List<ProjectDTOResponse> projectData = projectDao.projectByProejct(projectProviderData.getId());
            //多线程处理数据
            ExecutorService projectpool = Executors.newCachedThreadPool();
            CountDownLatch projectlatch = new CountDownLatch(projectData.size());
            ArrayList<Object> arrayLists = new ArrayList<>();
            if(null == projectData || projectData.size()<=0)continue;
            for (ProjectDTOResponse project : projectData){
                if (StringUtils.isBlank(project.getProjectName())
                        || StringUtils.isBlank(project.getId()))continue;
                //时间线
                ArrayList<String> timelineSet = new ArrayList<>();
                List list = assemblyProjectData(project);
                if (null != list && list.size()>0){
                    timelineSet.addAll(list);
                }
                //开启线程
                Runnable run = new Runnable() {
                    public void run() {
                        try {
                            //动态更新数据
                            List<UpdateDynamicsDTOResponse> updateNamicsList = updatedynamicsDao.getUpdateNamicsByProId(project.getId());
                            if (null == updateNamicsList || updateNamicsList.size()<=0)return;

                            ArrayList<Future<List>> arrayList = new ArrayList<>();
                            ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
                            try {
                                updateNamicsList.forEach(upEntity -> {
                                    Future<List> submit = executorService.submit(() -> assemblyUpdateDymicData(upEntity));
                                    arrayList.add(submit);
                                });
                            }catch (Exception e){
                                log.info("动态更新数据线程报错：【{}】",e);
                            }finally {
                                executorService.shutdown();
                            }

                            arrayList.forEach(f -> {
                                try {
                                    if (null != f.get() && f.get().size()>0){
                                        timelineSet.addAll(f.get());
                                    }
                                } catch (Exception e) {
                                    log.info("动态更新数据线程报错：【{}】",e);
                                }
                            });
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            projectlatch.countDown();
                        }
                    }
                };
                projectpool.execute(run);
                HashMap<String, Object> map = new HashMap<>();
                if (timelineSet.size()>0){
                    map.put("timeline",DataInfoUtil.strDatesort(timelineSet));
                }
                //项目名称
                map.put("projectName",project.getProjectName());
                arrayLists.add(map);
            }try {
                projectlatch.await(10, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                projectpool.shutdown();
            }
            //项目名称
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("proNameTimes",arrayLists);
            //项目方名称
            hashMap.put("projectProviderName",projectProviderData.getName());
            lists.add(hashMap);
        }
        return lists;
    }

    /*private List getProNameTime(List<ProjectProviderDTO> projectProviderList){
        ArrayList<Object> lists = new ArrayList<>();
        for (ProjectProviderDTO projectProviderData : projectProviderList){
            if(StringUtils.isBlank(projectProviderData.getId()))continue;
            //所有项目数据
            List<ProjectDTOResponse> projectData = projectDao.projectByProejct(projectProviderData.getId());
            //返回数据
            ArrayList<HashMap> repLists = new ArrayList<>();
            ExecutorService executorServicePro = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
            *//*projectData.forEach(proEntity -> {
                Future<HashMap> future = executorServicePro.submit(() -> {
                    if (StringUtils.isBlank(proEntity.getProjectName())
                            || StringUtils.isBlank(proEntity.getId())) return;
                    //时间线
                    ArrayList<String> timelineSet = new ArrayList<>();
                    List list = assemblyProjectData(proEntity);
                    if (null != list && list.size() > 0) {
                        timelineSet.addAll(list);
                    }

                    //动态更新数据
                    List<UpdateDynamicsDTOResponse> updateNamicsList = updatedynamicsDao.getUpdateNamicsByProId(proEntity.getId());
                    if (null == updateNamicsList || updateNamicsList.size() <= 0) return;
                    ArrayList<Future<List>> arrayList = new ArrayList<>();
                    ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
                    updateNamicsList.forEach(upEntity -> {
                        Future<List> submit = executorService.submit(() -> assemblyUpdateDymicData(upEntity));
                        arrayList.add(submit);
                    });
                    arrayList.forEach(f -> {
                        try {
                            if (null != f.get() && f.get().size() > 0) {
                                timelineSet.addAll(f.get());
                            }
                        } catch (Exception e) {
                            log.info("动态更新数据线程报错：【{}】", e);
                        }
                    });
                    HashMap<String, Object> map = new HashMap<>();
                    if (timelineSet.size() > 0) {
                        map.put("timeline", DataInfoUtil.strDatesort(timelineSet));
                    }
                    //项目名称
                    map.put("projectName", proEntity.getProjectName());
                    return map;
                });
                repLists.add(future);
            });*//*
            //项目名称
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("proNameTimes",repLists);
            //项目方名称
            hashMap.put("projectProviderName",projectProviderData.getName());
            lists.add(hashMap);
        }
        return lists;
    }*/

    private List assemblyUpdateDymicData(UpdateDynamicsDTOResponse updateDynamics){
        Set<String> set = new HashSet<>();
        ArrayList<String> timelineSet = new ArrayList<>();
        if (StringUtils.isNotBlank(updateDynamics.getFinancingPeriod())){
            if (set.add(updateDynamics.getFinancingPeriod()))
                timelineSet.add(updateDynamics.getFinancingPeriod());
        }
        if (StringUtils.isNotBlank(updateDynamics.getTechnologyAuthenticationDate())){
            if (set.add(updateDynamics.getTechnologyAuthenticationDate()))
                timelineSet.add(updateDynamics.getTechnologyAuthenticationDate());
        }
        if (StringUtils.isNotBlank(updateDynamics.getMarketDevelopmentDate())){
            if (set.add(updateDynamics.getMarketDevelopmentDate()))
                timelineSet.add(updateDynamics.getMarketDevelopmentDate());
        }
        if (StringUtils.isNotBlank(updateDynamics.getTimetoMarket())){
            if (set.add(updateDynamics.getTimetoMarket()))
                timelineSet.add(updateDynamics.getTimetoMarket());
        }
        if (StringUtils.isNotBlank(updateDynamics.getAwardDate())){
            if (set.add(updateDynamics.getAwardDate()))
                timelineSet.add(updateDynamics.getAwardDate());
        }
        return timelineSet;
    }

    private List assemblyProjectData(ProjectDTOResponse project){
        //时间线
        ArrayList<String> timelineSet = new ArrayList<>();
        Set<String> projectset = new HashSet<>();
        /**
         * 对接时间
         */
        if (StringUtils.isNotBlank(DataInfoUtil.getSingleSelection(project.getStatus()))){
            String status = DataInfoUtil.getSingleSelection(project.getStatus());
            if ("已对接 Docked".equals(status)){
                if (StringUtils.isNotBlank(project.getStatusUpdateTime())){
                    if (projectset.add(project.getStatusUpdateTime()))
                        timelineSet.add(project.getStatusUpdateTime());
                }
            }
        }
        /**
         * 创建时间
         */
        if (StringUtils.isNotBlank(project.getCreatedTime())){
            if (projectset.add(project.getCreatedTime()))
                timelineSet.add(project.getCreatedTime());
        }
        return timelineSet;
    }
}
